Skip to content

malformed input file can hang flex #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hannob opened this issue Nov 21, 2016 · 4 comments
Closed

malformed input file can hang flex #128

hannob opened this issue Nov 21, 2016 · 4 comments

Comments

@hannob
Copy link

hannob commented Nov 21, 2016

The attached file will hang flex, probably causing it to be stuck in an infinite loop. It's only one line, so it can also easily be tested on the command line:

echo '%option 8bit prefix="yywrap%"' | flex

This was found with the fuzzing tool american fuzzy lop. Tested with the current git code of flex.
flex-hang.zip

@DemiMarie
Copy link
Contributor

M4 is stuck in a loop because M4_YY_PREFIX expands to yywrap%, but yywrap expands to M4_YY_PREFIX[[wrap]]m4_ifelse($#, 0,,[[($@)]]). Hence there is an infinite loop of recursive macro calls.

Flex should overquote the definition of M4_YY_PREFIX to prevent this from happening, as well as forbidding it from including [ or ]. That would just cause a C syntax error in the generated code anyway.

@DemiMarie
Copy link
Contributor

DemiMarie commented Nov 29, 2016

I wonder if it would be best to rip out the use of M4 from Flex entirely, at least at (Flex) run-time. It has been a giant bug farm (see most of my patches, as well as this bug), is slow (since it involves an extra process), and is not easy to install on Windows. Furthermore, Flex uses very few of M4's features – it uses no recursive macros, for example. M4 is a full Turing-complete programming language, but Flex has no need for this feature.

It would be much cleaner for Flex to handle all templating internally. That would eliminate the need for M4 altogether, except perhaps at build-time (where the problems don't arise).

If we are willing to build-depend on a scripting language (even Awk would work), we could have a script compile the skeleton file into compilable C code that handled the templating itself, with no need for M4.

This would be much easier in C++, due to the C++ Standard Library containers.

@westes
Copy link
Owner

westes commented Nov 29, 2016 via email

@westes
Copy link
Owner

westes commented Dec 29, 2016

This has been fixed on flex master and will be included in the next release of flex.

@westes westes closed this as completed Dec 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants